/**
*	@file TNode.h
*
*	@brief this header file is defining table structure
*
*	@author li yuchen
*
*	@date 1/28/2011
*/  
#ifndef TNode_H
#define TNode_H

#include <iostream>
#include <string>
using namespace std;

/**	@brief describe different type of Tnode in AST */
enum TNodeType{
	/** procedure type */
	PROC_TYPE,       

	/** operator type */
	OP_TYPE,         

	/** variable type */
	VAR_TYPE,      

	/** constant type */
	CONST_TYPE,      

	/** assignment type */
	ASSIGN_TYPE,  

	/** while loop type */
	WHILE_TYPE,      

	/** if-else type */
	IF_TYPE,    

	/** call type */
	CALL_TYPE,       

	/** statement list type */
	STMT_LIST_TYPE,	 

	/** root type */
	ROOT,          


	/**	for query processor build, stmt_type or prog_line */
	STMT_TYPE,
};

string TNodeTypeToString(TNodeType type);

/**
*	@brief different purpose for different node
*	procedure node: procedure index in procedure table
*	opeartor node: integer value of ['+'|'-'|'*']
*	statement list node: not applicable
*	proc node: proc index in proc table
*	constant node: the value itself
*	call node: the procedure index of the procedure called
*	assignment,if,while,statement list nodes: not applicable
*	stmt_type is not relevent
*/
typedef int TNodeValue;

/**
*	@brief this is NOT_APPLICABLE to procedure
*	for type assign, while, if, call it means the stmt number of the node
*	for stmt_list, operator and variable it means the count number from 0 which is done in parser
*	STMT_TYPE is not relevent
*/
typedef int StmtNum; 

/** start from 1 */
typedef int AssignNum;
typedef int CallNum;
typedef int WhileNum;
typedef int IfNum;

/**	@brief whenever the TNodeValue and StmtNum is not applicable to the TNode, put this constant */
#define NOT_APPLICABLE  -1

struct TNode{
	/**	@brief type of the TNode */
	TNodeType type;

	/**	@brief value of the TNode if applicable */
	TNodeValue value;

	/** @brief statement number of the TNode if applicable */
	StmtNum stmt_num;
	
	TNode* parent;
	TNode* child;
	TNode* right_sibling;
	TNode* left_sibling;
};

#endif